<?php
/* 
 * Wymiana danych w kontrolerze modułowym
 */

class ControllerDataExchange {

	public static function Get($variable) {
		$index = self::Init();
		if(isset($index[$variable])) {
			return $index[$variable];
		} else {
			throw new UserException('Niezdefiniowana zmienna: '.$variable.' w indeksie ControllerDataExchange');
		}
	}

	public static function Exists($variable) {
		$index = self::Init();
		if(isset($index[$variable])) {
			return true;
		} else {
			return false;
		}
	}

	public static function Set($variable, $value) {
		$index = self::Init();
		$index[$variable] = $value;
		self::Save($index);
	}

	private static function Init() {
		if(Registry::Exists('ControllerDataExchange')) {
			return Registry::Get('ControllerDataExchange');
		} else {
			return array();
		}
	}

	private static function Save($index) {
		if(Registry::Exists('ControllerDataExchange')) {
			return Registry::Remove('ControllerDataExchange');
		}

		Registry::Set('ControllerDataExchange', $index);
	}
}

